<?php
echo $html->script(array("fckeditor"));
$this->Html->addCrumb('Add Item');
?>
<div class="products form">
    <?php 
    if(isset($limitCross) && $limitCross=="Yes"){
    echo $this->Session->flash(); 
    }else{
    ?>
    <div id="result">
        <div class="search-title">Add Item</div>
        <br />
        <?php echo $this->Form->create('Product', array('type' => 'file')); ?>
        <?php
        echo $this->Form->input('user_id', array('type' => 'hidden', 'value' => $session->read('Auth.User.id')));
        ?>
        <input type="hidden" id="hiddencatid" />
        <div class="search-title">1. Create a descriptive title for your item</div>
        <fieldset class="creat-product">
            <em>*</em>
            <?php
            echo $this->Form->input('products_title', array('label' => false, 'div' => false, 'title' => 'Create a descriptive title for your item', 'class' => 'required', 'size' => '105'));
            ?>
        </fieldset>

        <div class="select-category">
            <div class="search-title">2. Select Category </div>	
            <div class="breadcrumb"></div>	
            <fieldset>
                <div class="selectcatstyle firstlabel hideContent"></div>
                <div class="selectcatstyle secondlabel hideContent"></div>
                <div class="selectcatstyle thirdlabel hideContent"></div>
                <div class="selectcatstyle fourthlabel hideContent"></div>
            </fieldset>	
        </div>	
        <div class="select-category">
            <div class="search-title">3. Bring your item to life with pictures</div>
            <p>We require certain photos for authenticity verification.  You can also include other photos to help your item stand out to Buyers and bring it to life!</p>
            <div class="photo-upload-left">

                <p>All images should be a jpg, png, gif or jpeg and be under 1mb in size</p>
                <div id="addanotherimage">

                </div>
            </div>
            <div class="photo-upload-right">
                <fieldset><strong>Gallery Image</strong><em>*</em><?php echo $this->Form->input('fileName', array('type' => 'file', "class" => "required validatefiletype", 'label' => false, 'div' => false)); ?></fieldset>
            </div>
            <br style="clear:both;" />
            <br style="clear:both;" />
            <br />
        </div>	


        <div class="select-category">
            <div class="search-title">4. Describe your item specifications</div>
            <p>We require item specifications to help Buyers find your items.</p>
            <div class="select-item-info">
                <fieldset>
                    <label>Global Brands<em>*</em></label>	
                    <!--			<div class="GlobalBrands hideContent"></div>-->
                    <div class="GlobalBrands">
                        <?php
                        echo $this->Form->input('Product.sugestbrands', array("div" => false, "label" => false, "id" => "autobrand", 'maxlength' => false, 'class' => 'required'));
                        echo $this->Form->hidden('Product.global_brands', array("div" => false, "label" => false, "id" => "autoComplete1"));
                        ?>
                    </div>
                </fieldset>
                <fieldset>
                    <label>Global Styles<em>*</em></label>				
                    <!--			<div class="GlobalStyles hideContent"></div>-->
                    <div class="GlobalStyles">
                        <?php
                        echo $this->Form->input('Product.sugeststyles', array("div" => false, "label" => false, "id" => "autostyle", 'maxlength' => false, 'class' => 'required'));
                        echo $this->Form->hidden('Product.global_styles', array("div" => false, "label" => false, "id" => "autostyle1"));
                        ?>
                    </div>
                </fieldset>			
                <fieldset>
                    <label>Global Conditions<em>*</em></label>									
                    <div class="GlobalConditions">
                        <?php
                        echo $this->Form->input('Product.sugestconditions', array("div" => false, "label" => false, "id" => "autocondition", 'maxlength' => false, 'class' => 'required'));
                        echo $this->Form->hidden('Product.global_conditions', array("div" => false, "label" => false, "id" => "autocondition1"));
                        ?>
                    </div>
                </fieldset>	
                <div class="AdditionalFields hideContent"></div>		
            </div>	

            <div class="item-size-info">
                <strong class="specific-item">Size Information</strong>
                <fieldset>
                    <div class="Sizes hideContent"></div>
                </fieldset>
                <br><br>If the item has damage or defects, describe them (optional)<br>
                <?php
                echo $this->Form->input('products_damage', array('div' => false, "label" => false, "rows" => 8, "cols" => 53));
                ?>	</div>

        </div>	


        <div class="select-category">
            <div class="search-title">5. Describe your item</div>
            <p>Include any additional details about your item you think the Buyer might want to know.</p>
            <?php
            echo $this->Form->input('products_description', array('div' => false, "label" => false, "rows" => 5, "cols" => 100, "class" => "fckrequired", "style" => "width:766px; margin:10px 0;"));
            ?>
<?php echo $fck->load('ProductProductsDescription', 'Basic'); ?>
            <br />Space left: <span id="counter2"></span> of 2000 characters
        </div>

        <div class="select-category">
            <div class="search-title">6. Specify Stock Quantity, Price &amp; Negotiation</div>
            <p>Decide whether you’d like to accept negotiation on the price or if you’d prefer a fixed price.</p>
            <fieldset class="stock-quantity">
                <table><tr><td><label><b>Price</b> <em>*</em></label></td><td><?php echo $this->Form->input('products_price', array("label" => false, "div" => false, "class" => "required number")); ?></td>
                        <td><label><b>Commission Fee</b></label></td><td>$0.00</td><td>
                            <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Quantity</b> <em>*</em></label></td><td><?php echo $this->Form->input('products_quantity', array("label" => false, "div" => false, "class" => "required digits")); ?></td>
                            <!--td><label><b>Weight</b></label></td><td><?php echo $this->Form->input('products_weight', array("label" => false, "div" => false)); ?></td-->
                    </tr></table>
            </fieldset>

            <fieldset class="stock-quantity">
                <?php
                echo $this->Form->input('negotiable', array("div" => false, "type" => "checkbox", "label" => false, "checked" => "checked", "value" => "Yes", "class" => "checkBox-position"));
                ?><label>Make this product negotiable</label>	
                <p class="sub-option">		
                    <?php echo $this->Form->input('leastprice', array("div" => false, "type" => "checkbox", "label" => false, "class" => "checkBox-position")); ?>
                    <label>Automatically accept offers of at least $&nbsp;</label>
<?php echo $this->Form->input('products_offerAcceptLeastPrice', array("div" => false, "label" => false, "disabled" => "disabled", "size" => 10)); ?>
                </p>
                <p class="sub-option">
                    <?php echo $this->Form->input('lowerprice', array("div" => false, "type" => "checkbox", "label" => false, "class" => "checkBox-position")); ?>
                    <label>Automatically decline offers lower than $</label>
<?php echo $this->Form->input('products_offerDeclineLowerPrice', array("div" => false, "label" => false, "disabled" => "disabled", "size" => 10)); ?>
                </p>		
            </fieldset>	
        </div>
        <div class="select-category">	
            <div class="search-title">7. Set shipping options</div>
            <div class="shippingmethod">
                    <?php if ($shippings): ?>
                    <fieldset>
    <?php echo $this->Form->input('ProductShippingMethods', array('id' => 'ProductShippingMethod', 'div' => false, 'label' => false, 'options' => $shippings, 'empty' => 'Select Shipping Method')); ?>
                        <label style="padding:0 25px 0 10px;"><b>Flat Cost :</b> $<span id="flatcost">0.00</span></label>
                        <input type="button" class="button" value="Add" name="addflatcost" id="addflatcost">
                    </fieldset>
                    <div class="shippingmethods shipping-left">
                        <div class="search-title">Selected Shipping Methods</div>
                        <table width="100%" border="0">
                            <tr><th width="65%"><b>Shipping Method</b></th>
                                <th width="15%"><b>Flat Cost</b></th>
                                <th width="15%"><b>Action</b></th>
                            </tr>			
                        </table>
                        <div id="loader_domestic_shipping" style="text-align:left;display:none;"><img alt="Adding shipping methods..." src="../img/loading.gif">Adding shipping methods...</div>
                        <div class="handalingtime shipping-right">
                            <fieldset>
                                <label style="padding:0 20px 0 10px;"><b>Handling Time<em>*</em> :</b></label>
    <?php echo $this->Form->input('handletime_id', array('id' => 'handalingtime', 'class' => 'required', 'div' => false, 'label' => false, 'options' => $handalingtimes, 'empty' => 'Select a Handling Time')); ?>

                            </fieldset>
                            <p><b>Additional info:</b><br /><span style="font-size:12px;">Max <span id="counter"></span> characters</span></p>		
                            <textarea id="HandaleAdditionalInfo" name="data[Product][handale_additional_info]" style="width:740px;height:120px;"><?php if (isset($this->data['handale_additional_info']))
        echo $this->data['handale_additional_info']; ?></textarea>
                    <?php //echo $fck->load('HandaleAdditionalInfo', 'Custom'); ?>
                        </div>
                    </div>
                <?php else: ?>
                    <span class="error_text">No shipping method found.</span>
<?php endif; ?>
            </div>
        </div>
        <div class="select-category">	
            <div class="search-title">8. International shipping</div>
            <fieldset>
                <p id="internationalShippingOption">
                    <?php
                    $options = array('Yes' => 'Provide International Shipping', 'No' => 'International Shipping Not Allowed');
                    $attributes = array('value' => 'Yes', 'legend' => false, "div" => false, "label" => false, "class" => "btn-radio", "style" => "margin:10px;");
                    echo $this->Form->radio('product_international_shipping', $options, $attributes);
                    ?>		
                </p>
            </fieldset>	
            <div class="internationalshipping">
                <table cellspacing="0" width="98%">
                    <tr><th width="50%" align="left">Shipping Method</th><th width="15%">Location(s)</th><th width="15%">Flat Shipping Cost</th><th width="10%">Action</th></tr>
                </table>
                <div id="loader_international_shipping" style="text-align:left;display:none;"><img alt="Adding shipping methods..." src="../img/loading.gif">Adding shipping methods...</div>		
            </div>
            <table id="internationlashippingform" width="98%">
                <tr>
                    <td valign="top" align="right">Shipping Method :</td><td>&nbsp;</td><td  align="left" valign="top">
                        <?php
                        echo $this->Form->input('internationalshippingmethod', array('id' => 'ProductInternationalshippingmethod', "div" => false, "label" => false, 'options' => $shippings, 'style' => 'width:280px', 'empty' => 'Select Shipping Method'));
                        ?></td><td>&nbsp;</td><td>Flat Shipping Cost : $</td><td><?php echo $this->Form->input('internationalshippingcost', array("div" => false, "label" => false, "size" => 10)); ?></td>
                </tr>
                <tr>
                    <td valign="top" align="right">&nbsp;Shipping Location :</td><td>&nbsp;</td><td align="left" valign="top">
                        <?php
                        $internationalocations_custom = $internationalocations;
                        $options2[''] = "Select Shipping Location";
                        $options2 = array_merge($options2, $internationalocations);
                        $internationalocations['worldwide'] = "Worldwide";
                        $internationalocations['custom_location'] = "Custom Location";

                        echo $this->Form->input('internationalshippinglocation', array("div" => false, "label" => false, 'options' => $internationalocations));
                        ?></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
                </tr>
                <tr id="custom_location" style="display:none;">
                    <td valign="top" colspan="6">&nbsp;&nbsp;&nbsp;Custom Location :
                        <?php
                        foreach ($internationalocations_custom as $key => $val):
                            echo'<input type="checkbox" name="data[customlocation][]" value="' . $key . '" />&nbsp;' . $val . '&nbsp;';
                        endforeach;
                        ?></td>
                </tr>
                <tr>
                    <td valign="top"></td><td>&nbsp;</td><td valign="top">
                    </td><td>&nbsp;</td><td>&nbsp;</td><td><input class="button" type="button" name="cancel"  id="cancelInternationaShipping" value="Cancel" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input class="button" type="button" id="saveInternationaShipping" name="save" value="Save" /></td>
                </tr>

            </table>	
            <input class="button"  type="button" name="addAnotherShipping" value="Add Another" style="display:none;" />
            <input type="hidden" name="addShippingCounter" id="addShippingCounter" value="0" />
            <p>&nbsp;</p>
            <p style="padding-left:10px;">Additional Info :<br /><span>Max <span id="counter4"></span> characters</span></p>
            <textarea id="InternationalShippingAdditionalInfo" name="data[Product][international_shipping_additional_info]" style="width:742px;height:120px;margin:10px;"></textarea>

        </div>
        <div class="select-category">
            <div class="search-title">9. Return Policy</div>
            <p>All Sellers must specify a Return Policy, even if the policy is that you do not accept returns. We encourage you to work with Buyers if there are any problems.</p>
            <fieldset style="padding:0 10px;">
                    <?php echo $this->Form->input('products_returnPolicyType', array("value" => "Yes", "div" => false, "label" => false, "type" => "checkbox", "class" => "checkBox-position")); ?><label>Display global Return Policy for this product</label>
                <p style="width:215px; ">
        <!--            Space left: <span id="counter3"></span> of 2000 characters-->
                    <?php echo '<br>Space left: <span id="returnplicy"></span> of 2000 characters'; ?>
                </p>
                <div id="return_policy">
                    <?php
                    echo $this->Form->textarea('products_returnPolicy', array("div" => false, "label" => false, "style" => "width:755px; height:200px; margin:10px 0;", "class" => "fckrequired"));
                    ?>
<?php echo $fck->load('ProductProductsReturnPolicy', 'Basic'); ?>
                </div>
            </fieldset>
        </div>	
        <div class="select-category">
            <div class="search-title">10. Additional Options</div>
            <fieldset class="add-option">
                <label class="label-add-option">Auto Re-list</label> <p class="check-add-option">
<?php echo $this->Form->input('auto_re_list', array("div" => false, "type" => "checkbox", "label" => false, "checked" => "checked", "value" => "Yes", "class" => "checkBox-position")); ?>
                    Yes, enable automatic re-listing of this item after expiry</p>
            </fieldset>
            <fieldset class="add-option">
                <label class="label-add-option">Block buyers</label>
                <p class="check-add-option">
                    <input type="checkbox" class="checkBox-position" id="block_country_check" />
<?php echo $this->Form->input("block_country", array('id' => 'block_country', 'type' => 'hidden')); ?>
                    <a href="javascript:void(0);" controller="products" action="blockcountry" onclick="showPop(this);">Who are registered in countries to which I don't ship</a>
                </p>
            </fieldset>
            <fieldset class="add-option">
                <label class="label-add-option">Salse Tax</label> <p class="check-add-option">
                    <input type="checkbox" name="data[Product][tax_us]" value="Yes" class="checkBox-position" />Sales Tax for US&nbsp;&nbsp;
                    <a href="javascript:void(0);" controller="salestaxes" action="index" onclick="showPop(this);">Refer To Sales Tax Table</a></p>
            </fieldset>
            <fieldset class="add-option">
                <label class="label-add-option">Payment</label>
                <p class="check-add-option">	
                    <?php echo $this->Form->input("use_paypal", array("type" => "checkbox", "div" => false, "label" => false, "checked" => "checked", "value" => "Yes", "class" => "checkBox-position")); ?>Accept Payment through PayPal <br />
                        <!--input type="text" name="data[Product][paypal]" value="<?php echo $session->read('Auth.User.paypal'); ?>" class="checkBox-position" /><br /-->
<?php echo $this->Form->input("use_google_checkout", array("type" => "checkbox", "div" => false, "label" => false, "checked" => "checked", "value" => "Yes", "class" => "checkBox-position")); ?>Accept Payment through Google Checkout
                        <!--input type="text" name="data[Product][google_checkout]" value="<?php echo $session->read('Auth.User.google_checkout'); ?>" class="checkBox-position" /><br /-->
                </p>
            </fieldset>
        </div>
        <div class="submit"><input type="submit" class="button" name="addproduct" value="Save"></div>
        </form>
    </div>
    <?php }?>
</div>
<?php //echo $html->script(array("jquery.form.js","jquery.validate.js","jquery.simplyCountable","jquery.autocomplete.js",'jqret/jquery.rte.js')); ?>
<?php echo $html->script(array("jquery.form.js", "jquery.validate.js", "jquery.simplyCountable", "jquery.autocomplete.js")); ?>

<script type="text/javascript">
    jQuery(document).ready(function(){

        jQuery.validator.addMethod("fckrequired", function (value, element) {
            var oEditor = FCKeditorAPI.GetInstance('ProductProductsDescription') ;
            var pageValue = oEditor.GetHTML(true);
            pageValue=jQuery.trim(pageValue);
            if ( pageValue == "<br />" || pageValue == "") {
                return false;
            }else{
                return true;
            }
        }, "This field is required.");

        jQuery('#ProductProductsReturnPolicy').simplyCountable({
            counter: '#returnplicy',
            countType: 'characters',
            maxCount: 2000,
            countDirection: 'down'
        });

        jQuery('#ProductProductsDescription').simplyCountable({
            counter: '#counter2',
            countType: 'characters',
            maxCount: 2000,
            countDirection: 'down'
        });
        
        jQuery("#ProductProductsReturnPolicyType").click(function(){
            if(this.checked==true)
                jQuery("#return_policy").fadeIn("250").hide();
            else
                jQuery("#return_policy").fadeOut("250").show();
        });
        jQuery.validator.addMethod("brandrequired", function (value, element) {
            var pageValue=jQuery("#sugestbrands").val();
            if ( pageValue == "Enter Brand" || pageValue == "") {
                return false;
            }else{
                return true;
            }
        }, "This field is required.");
        jQuery.validator.addMethod("stylerequired", function (value, element) {
            var pageValue=jQuery("#sugeststyles").val();
            if ( pageValue == "Enter Style" || pageValue == "") {
                return false;
            }else{
                return true;
            }
        }, "This field is required.");
        jQuery.validator.addMethod("conditionrequired", function (value, element) {
            var pageValue=jQuery("#sugestconditions").val();
            if ( pageValue == "Enter Condition" || pageValue == "") {
                return false;
            }else{
                return true;
            }
        }, "This field is required.");

        var v = jQuery("#ProductAddForm").validate({
            submitHandler: function(form) {
                jQuery(form).ajaxSubmit({
                    target: "#result"
                });
            }
        });
		
        jQuery("a.removeanotherimage").live('click',function(){		
            var currentTotalImg=jQuery("#totalImage").val();
            var currentImgIndex=parseInt(currentTotalImg)-1;
            jQuery("#totalImage").val(currentImgIndex);
            jQuery(this).parent().parent().remove();
        });		
        //Load Parent Category
        var url= baseurl+"products/fetchParentCategory/";
        jQuery(".firstlabel").show().fadeIn("slow");
        jQuery(".firstlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Parent Category...");
        jQuery.get(url, function(data) {
            jQuery('.firstlabel').html(data);
        });
	
        //Add Another Image
        jQuery("input[id=addAnotherImage]").live('click',function(){
            var currentTotalImg=jQuery("#totalImage").val();
            if(currentTotalImg<=15){
                var currentImgIndex=parseInt(currentTotalImg);
                var html='<tr><td align="left"><span id="span_'+currentImgIndex+'">Image '+currentImgIndex+'</td><td> <input type="file" class="validatefiletype" id="ProductFileName'+currentImgIndex+'" name="data[Product][fileName'+currentImgIndex+']" /></td><td><a href="javascript:void(0);" class="removeanotherimage"><img alt="delete image" src="'+baseurl+'img/icoerror.png"></a>';
                html+='<input type="hidden" value="0" name="data[ProductImage]['+currentImgIndex+'][imagetitle_id]" /><input type="hidden" value="No" name="data[ProductImage]['+currentImgIndex+'][required]" /></span></td></tr>';
                var currentImgIndex=parseInt(currentTotalImg)+1;
                jQuery("#totalImage").val(currentImgIndex);
                jQuery(html).insertAfter("#addanotherimage table tr:last");
            }		
        });
	
        jQuery("#ProductCategoryId").live('click',function(){
            var url= baseurl+"products/fetchSubCategory/"+this.value;
            jQuery("#hiddencatid").val(this.value);
            catid=this.value;
            var breadcrumb="";
		
            //Load Second label Sub category
            if(jQuery(this).parent().next().hasClass('secondlabel')){
                breadcrumb="<p><em>*</em> Current category: <span>"+jQuery(".firstlabel select option:selected").text()+"</span></p>";
                jQuery("#hiddencatid").val(this.value);
                catid=jQuery("#hiddencatid").val();
                jQuery(".fourthlabel").hide().fadeOut("slow");
                jQuery(".thirdlabel").hide().fadeOut("slow");
                jQuery(".secondlabel").show().fadeIn("slow");
                //Load Sub category
                jQuery(".secondlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Subcategory...");			
			
                jQuery.get(url, function(data) {
                    jQuery('.secondlabel').html(data);		  
                });
                loadImages(this.value);	
                //loadBrand(this.value);
                //loadStyle(this.value);
                //loadCondition(this.value);
                loadAdditionalFields(this.value);
                loadSizes(this.value);
                loadShippingMethod(this.value);
            }
	
            //Load Third label Sub category
            if(jQuery(this).parent().hasClass('secondlabel'))
            {
                jQuery("#hiddencatid").val(this.value);
                catid=jQuery("#hiddencatid").val();
                jQuery(".fourthlabel").hide().fadeOut("slow");
                jQuery(".thirdlabel").hide().fadeOut("slow");			
			
                jQuery(".thirdlabel").show().fadeIn("slow");			
                if(this.value==0){return false;}
                breadcrumb="<p><em>*</em> Current category: <span>"+jQuery(".firstlabel select option:selected").text()+" >> "+jQuery(".secondlabel select option:selected").text()+"</span></p>";
                jQuery(".thirdlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Subcategory...");
                jQuery.get(url, function(data) {
                    jQuery('.thirdlabel').html(data);		  
                });
                loadImages(this.value);	
                //loadBrand(this.value);
                //loadStyle(this.value);
                //loadCondition(this.value);
                loadAdditionalFields(this.value);
                loadSizes(this.value);
                loadShippingMethod(this.value);
            }
		
            //Load Fourth label Sub category
            if(jQuery(this).parent().hasClass('thirdlabel'))
            {			
                jQuery("#hiddencatid").val(this.value);
                catid=jQuery("#hiddencatid").val();
                jQuery(".fourthlabel").show().fadeIn("slow");
                if(this.value==0){return false;}
                breadcrumb="<p><em>*</em> Current category: <span>"+jQuery(".firstlabel select option:selected").text()+" >> "+jQuery(".secondlabel select option:selected").text()+" >> "+jQuery(".thirdlabel select option:selected").text()+"</span></p>";
                jQuery(".fourthlabel").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Subcategory..");
                jQuery.get(url, function(data) {
                    jQuery('.fourthlabel').html(data);		  
                });
                loadImages(this.value);	
                //loadBrand(this.value);
                //loadStyle(this.value);
                //loadCondition(this.value);
                loadAdditionalFields(this.value);
                loadSizes(this.value);
                loadShippingMethod(this.value);
            }
		
            //Load Fourth label Sub category
            if(jQuery(this).parent().hasClass('fourthlabel'))
            {
                if(this.value==0){return false;}
                jQuery("#hiddencatid").val(this.value);
                catid=jQuery("#hiddencatid").val();
                breadcrumb="<p><em>*</em> Current category: <span>"+jQuery(".firstlabel select option:selected").text()+" >> "+jQuery(".secondlabel select option:selected").text()+" >> "+jQuery(".thirdlabel select option:selected").text()+" >> "+jQuery(".fourthlabel select option:selected").text()+"</span></p>";			
                loadImages(this.value);	
                //loadBrand(this.value);
                //loadStyle(this.value);
                //loadCondition(this.value);
                loadAdditionalFields(this.value);
                loadSizes(this.value);
                loadShippingMethod(this.value);
            }
		
            //Generate breadcrumb
            jQuery('.breadcrumb').html(breadcrumb);	
            
            jQuery('#autobrand').keyup(function() {
                jQuery('#autoComplete1').val('');
            });
            jQuery('#autostyle').keyup(function() {
                jQuery('#autostyle1').val('');
            });
            jQuery('#autocondition').keyup(function() {
                jQuery('#autocondition1').val('');
            });


            jQuery("#autobrand").autocomplete(baseurl+"/products/autobrand/"+catid+'/brand',
            {
                delay:10,
                minChars: 1,
                cacheLength: 1,
                onItemSelect:selectItem,
                onFindValue:findValue,
                formatItem: formatItem,
                autoFill: false
            });

            jQuery("#autostyle").autocomplete(baseurl+"/products/autobrand/"+catid+'/style',
            {
                delay:10,
                minChars: 1,
                cacheLength: 1,
                onItemSelect:selectItemst,
                onFindValue:findValuest,
                formatItem: formatItem,
                autoFill: false
            });

            jQuery("#autocondition").autocomplete(baseurl+"/products/autobrand/"+catid+'/condition',
            {
                delay:10,
                minChars: 1,
                cacheLength: 1,
                onItemSelect:selectItemcon,
                onFindValue:findValuecon,
                formatItem: formatItem,
                autoFill: false
            });

            function selectItem(li) {
                findValue(li);
            }

            function findValue(li) {
                //console.log(li)

                // if coming from an AJAX call, let's use the product id as the value
                if( !!li.extra ) var sValue = li.extra[0];
                else
                    var sValue = li.selectValue;
                jQuery('#autoComplete1').val(sValue);
                // alert("The value you selected was: " + sValue);
            }

            function selectItemst(li) {
                findValuest(li);
            }

            function findValuest(li) {
                //console.log(li)

                // if coming from an AJAX call, let's use the product id as the value
                if( !!li.extra ) var sValue = li.extra[0];
                else
                    var sValue = li.selectValue;
                jQuery('#autostyle1').val(sValue);
                // alert("The value you selected was: " + sValue);
            }

            function selectItemcon(li) {
                findValuecon(li);
            }

            function findValuecon(li) {
                //console.log(li)

                // if coming from an AJAX call, let's use the product id as the value
                if( !!li.extra ) var sValue = li.extra[0];
                else
                    var sValue = li.selectValue;
                jQuery('#autocondition1').val(sValue);
                // alert("The value you selected was: " + sValue);
            }

            function formatItem(row) {
                if(row[1] == undefined) {
                    return row[0];
                }
                else {
                    return row[0];
                    //return row[0] + " (id: " + row[1] + ")";
                }
            }
            function loadImages(Id){
                //Load Global brands for this category
                jQuery("#addanotherimage").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Images field...");
                var brandurl=baseurl+"products/fetchimages/"+Id;
                jQuery.get(brandurl, function(data) {
                    jQuery('#addanotherimage').html(data);
                });
            }		
            function loadBrand(Id){
                //Load Global brands for this category
                jQuery(".GlobalBrands").show().fadeIn("slow");
                jQuery(".GlobalBrands").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Global brands for selected category...");
                var brandurl=baseurl+"products/fetchbrand/"+Id;
                jQuery.get(brandurl, function(data) {
                    jQuery('.GlobalBrands').html(data);		  
                });
            }	
		
            function loadStyle(Id){
                //Load Global styles for this category
                jQuery(".GlobalStyles").show().fadeIn("slow");
                jQuery(".GlobalStyles").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Global styles for selected category...");
                var brandurl=baseurl+"products/fetchstyle/"+Id;
                jQuery.get(brandurl, function(data) {
                    jQuery('.GlobalStyles').html(data);		  
                });
            }	
		
            function loadCondition(Id){
                //Load Global conditions for this category
                jQuery(".GlobalConditions").show().fadeIn("slow");
                jQuery(".GlobalConditions").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Global conditions for selected category...");
                var brandurl=baseurl+"products/fetchcondition/"+Id;
                jQuery.get(brandurl, function(data) {
                    jQuery('.GlobalConditions').html(data);		  
                });
            }
            function loadAdditionalFields(Id){
                //Load additional fields for this category
                jQuery(".AdditionalFields").show().fadeIn("slow");
                jQuery(".AdditionalFields").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading Additional fields for selected category...");
                var brandurl=baseurl+"products/fetchadditionalfields/"+Id;
                jQuery.get(brandurl, function(data) {
                    jQuery('.AdditionalFields').html(data);		  
                });
            }
		
            function loadSizes(Id){
                //Load size title and value for this category
                jQuery(".Sizes").show().fadeIn("slow");
                jQuery(".Sizes").html("<img alt='loading...' src='"+baseurl+"/img/loading.gif'>loading size information for selected category...");
                var brandurl=baseurl+"products/fetchsizes/"+Id;
                jQuery.get(brandurl, function(data) {
                    jQuery('.Sizes').html(data);		  
                });
            }
            function loadShippingMethod(Id){
                //Load shipping method for this category			
                jQuery.ajax({
                    type: 'GET',
                    url: baseurl+"products/getshippingcost/"+Id,					
                    dataType: 'json',
                    success: function(data){
                        jQuery("#flatcost").html(data.shipping_cost);						
                        return false;
                    }			
                });
            }
				
        });
	
        jQuery("#ProductGlobalBrand").live('change',function(){
            if(this.value=="addanother"){
                html='<input id="sugestbrands" class="brandrequired" type="input" name="data[Product][sugestbrands]" id="sugestbrands" value="Enter Brand" onblur="';
                html+="if(this.value=='') this.value='Enter Brand'";
                html+='"';
                html+='onfocus="if(this.value==';
                html+="'Enter Brand') this.value='';";
                html+='">';
                jQuery(this).hide();	
                jQuery(this).after(html);
            }
        });
	
        jQuery("#sugestbrands").live('click',function(){
            //alert(this.value);
        });
	
        jQuery("#ProductGlobalStyle").live('change',function(){
            if(this.value=="addanother"){
                html='<input id="sugeststyles" class="stylerequired" type="input" name="data[Product][sugeststyles]" value="Enter Style" onblur="';
                html+="if(this.value=='') this.value='Enter Style'";
                html+='"';
                html+='onfocus="if(this.value==';
                html+="'Enter Style') this.value='';";
                html+='">';
                jQuery(this).hide();	
                jQuery(this).after(html);
            }	
        });
	
        jQuery("#ProductGlobalCondition").live('change',function(){
            if(this.value=="addanother"){
                html='<input id="sugestconditions" class="conditionrequired" type="input" name="data[Product][sugestconditions]" value="Enter Condition" onblur="';
                html+="if(this.value=='') this.value='Enter Condition'";
                html+='"';
                html+='onfocus="if(this.value==';
                html+="'Enter Condition') this.value='';";
                html+='">';
                jQuery(this).hide();	
                jQuery(this).after(html);
            }	
        });
	
        jQuery('input[id=addflatcost]').live('click',function(){
            var shipID=jQuery("select#ProductShippingMethod").val();		
            var shipCOST=jQuery("#flatcost").html();		
            err_msg="";
            if(shipID=="")
                err_msg+="You have to select a shipping method.";
            if(shipCOST=="0.00")
                err_msg+="\n\nShipping cost can not be $0.00. Please select a category.";
            if(err_msg==""){
                jQuery("#loader_domestic_shipping").show();
                jQuery.ajax({
                    type: 'GET',
                    url: baseurl+"products/getshippingmethods/"+shipID,					
                    dataType: 'json',
                    success: function(data){
                        var addRow=false;
                        jQuery('.shippingmethods table td').each(function(index) {							
                            if(data.shipping_method==jQuery(this).text()){
                                addRow=true;
                                return false;
                            }
                        });
                        if(addRow){
                            jQuery("#loader_domestic_shipping").hide();
                            alert("You already add this shipping method.");return false;						
                        }else{
                            jQuery("#loader_domestic_shipping").hide();
                            jQuery(".shippingmethods table").append("<tr><td style='border-width:0px;'>"+data.shipping_method+"</td><td style='border-width:0px;'>$"+shipCOST+"</td><td style='border-width:0px;'><a href='javascript:void(0);' class='deleteshipping' rowID='"+data.id+"'>Delete</a></td></tr>");						
                            jQuery("select#ProductShippingMethod").val("0");						
                            jQuery(".shippingmethods").append("<input type='hidden' class='ProductShippings_"+data.id+"' name='data[ProductShippings][]' value='"+data.id+"'>");
                            return false;
                        }
                    }			
                });
            }else{alert(err_msg);}	
        }); 
	
        jQuery('tr td a.deleteshipping').live('click',function(){
            var rowID=jQuery(this).attr("rowID");		
            jQuery(this).parent().parent().remove();	
            jQuery(".ProductShippings_"+rowID).val("");	
        });
	
        //International Shipping
        jQuery('tr td a.deleteinternationalshipping').live('click',function(){
            var rowID=jQuery(this).attr("rowID");
            if(confirm("Are you sure you want to remove this shipping method from this product?"))
            {
                jQuery('#rowINT_'+rowID).remove();
                jQuery(".ProductInternationalShippings_"+rowID).remove();
            }
            else
                return false;
		
        });
	
        jQuery("#saveInternationaShipping").click(function(){
            var err="";
            var PIS=jQuery("#ProductInternationalshippingmethod").val();
            if(PIS=="")
                err+="Please select a Shipping Method.\n";
            else
                var PIS_label=jQuery("#ProductInternationalshippingmethod option:selected").text();
            var PISC=jQuery("#ProductInternationalshippingcost").val();		
		
            if(PISC=="" || PISC=="0.00")
                err+="Please enter a valid Shipping Cost\n";
		
            var PISL=jQuery("#ProductInternationalshippinglocation").val();		
            if(PISL=="" || PISL==null)
                err+="Please select a Shipping Location.\n";		
            else		
            {				
                var PISL_label=jQuery("#ProductInternationalshippinglocation option:selected").text();
            }
            if(err!="")	
                alert(err);		
            else{
                jQuery("#loader_international_shipping").show();
                var i=jQuery("#addShippingCounter").val();						
                jQuery("#ProductInternationalshippingcost").html("0.00");
                jQuery("select#ProductInternationalshippingmethod").val("0");						
			
                jQuery(".internationalshipping table").append("<tr id='rowINT_"+i+"'><td style='text-align:left;'>"+PIS_label+"</td><td style='text-align:center;'>"+PISL_label+"</td><td style='text-align:center;'>$ "+PISC+"</td><td style='text-align:center;'><a href='javascript:void(0);' rowID='"+i+"' class='deleteinternationalshipping'>Delete</a></td></tr>");						
                jQuery(".internationalshipping").append("<input type='hidden' class='ProductInternationalShippings_"+i+"' name='data[ProductInternationalShippings]["+i+"][shipping_id]' value='"+PIS+"'><input type='hidden' class='ProductInternationalShippings_"+i+"' name='data[ProductInternationalShippings]["+i+"][continent_id]' value='"+PISL+"'><input type='hidden' class='ProductInternationalShippings_"+i+"' name='data[ProductInternationalShippings]["+i+"][shipping_cost]' value='"+PISC+"'>");
			
                i=parseInt(i)+1;
                jQuery("#addShippingCounter").val(i);
                jQuery("#loader_international_shipping").hide();
                return false;
            }	
        });
	
        jQuery("#ProductInternationalshippingmethod").change(function(){
            var PISL_val=jQuery(this).val();
            if(PISL_val > 0){
                var international_costurl=baseurl+"products/international_cost/"+PISL_val;			
                jQuery.get(international_costurl, function(data) {
                    //jQuery('select#valuearray').html(data);				
                });
            }
            else return false;
        });
	
        jQuery("#ProductInternationalshippinglocation").change(function(){
            var PISL_val=jQuery(this).val();
            if	(PISL_val=="worldwide"){
                jQuery("#custom_location").fadeOut().hide("250");
            }
            else if(PISL_val=="custom_location"){			
                jQuery("#custom_location").fadeIn("250").show();
            }
            else{ 
                jQuery("#custom_location").fadeOut("250").hide("250");
            }
        });
	
        jQuery('#ProductProductsReturnPolicy').simplyCountable({
            counter: '#counter3',
            countType: 'characters',
            maxCount: 2000,
            countDirection: 'down'
        });
        jQuery('#InternationalShippingAdditionalInfo').simplyCountable({
            counter: '#counter4',
            countType: 'characters',
            maxCount: 1000,
            countDirection: 'down'
        });
        jQuery('#HandaleAdditionalInfo').simplyCountable({
            counter: '#counter',
            countType: 'characters',
            maxCount: 1000,
            countDirection: 'down'
        });
        jQuery('p#internationalShippingOption input[type=radio]').click(function(){
            var shippFlag=jQuery(this).val();
            if(shippFlag=="Yes")
                jQuery("#internationlashippingform").fadeIn("250").show();
            else{
                jQuery("input[name=addAnotherShipping]").fadeOut("250").hide();		
                jQuery("#internationlashippingform").fadeOut("250").hide();
            }
        });
	
        jQuery('input[name=addAnotherShipping]').click(function(){
            jQuery("input[name=addAnotherShipping]").fadeOut("250").hide();
            jQuery("#internationlashippingform").fadeIn("250").show();
        });
        jQuery('#cancelInternationaShipping').click(function(){
            jQuery("input[name=addAnotherShipping]").fadeIn("250").show();
            jQuery("#internationlashippingform").fadeOut("250").hide();
        });
	
        jQuery("select#sizearray").live('change',function(){
            if(this.value!=""){
                var brandurl=baseurl+"products/fetchvaluearray/"+this.value;
                jQuery.get(brandurl, function(data) {
                    jQuery('select#valuearray').html(data);
                });
            }else{
                return false;
            }
        });
        jQuery("select#sizearray0").live('change',function(){
            if(this.value!=""){
                var brandurl=baseurl+"products/fetchvaluearray/"+this.value;
                //alert(brandurl);
                jQuery.get(brandurl, function(data) {
                    jQuery('select#valuearray0').html(data);
                });
            }else{
                return false;
            }		
        });
        jQuery("select#sizearray1").live('change',function(){
		
            if(this.value!=""){
                //var );	
                var brandurl=baseurl+"products/fetchvaluearray/"+this.value;
                //alert(brandurl);
                jQuery.get(brandurl, function(data) {
                    jQuery('select#valuearray1').html(data);				
                });
            }else{
                return false;
            }		
        });
        jQuery("select#sizearray2").live('change',function(){
		
            if(this.value!=""){
                var brandurl=baseurl+"products/fetchvaluearray/"+this.value;
                jQuery.get(brandurl, function(data) {
                    jQuery('select#valuearray2').html(data);				
                });
            }else{
                return false;
            }		
        });
        jQuery("select#sizearray3").live('change',function(){
		
            if(this.value!=""){			
                var brandurl=baseurl+"products/fetchvaluearray/"+this.value;
                jQuery.get(brandurl, function(data) {
                    jQuery('select#valuearray3').html(data);
                });
            }else{
                return false;
            }		
        });
	
        jQuery("#ProductLowerprice").click(function(){		
            if(jQuery(this).attr("checked")==true){
                jQuery("#ProductProductsOfferDeclineLowerPrice").removeAttr("disabled");
                jQuery("#ProductProductsOfferDeclineLowerPrice").addClass("required");
            }
            else{
                jQuery("#ProductProductsOfferDeclineLowerPrice").attr("disabled","disabled");
                jQuery("#ProductProductsOfferDeclineLowerPrice").removeClass("required");
            }
        });
        jQuery("#ProductLeastprice").click(function(){
            if(jQuery(this).attr("checked")==true){
                jQuery("#ProductProductsOfferAcceptLeastPrice").removeAttr("disabled");
                jQuery("#ProductProductsOfferAcceptLeastPrice").addClass("required");
            }
            else{	
                jQuery("#ProductProductsOfferAcceptLeastPrice").attr("disabled","disabled");
                jQuery("#ProductProductsOfferAcceptLeastPrice").removeClass("required");
            }
        });

        jQuery(".other_addfield").live('keyup',function(){
            fieldvalue=jQuery(this).val();
            fieldID=jQuery(this).attr("fieldID");
            jQuery('.fiels_label_'+fieldID).html('<img alt="Checking duplicate dropdown value" src="'+baseurl+'/img/loading.gif">');
            jQuery.ajax({
                type: 'GET',
                url: baseurl+"products/chkduplicatefield/"+fieldID+"/"+fieldvalue,					
                dataType: 'json',
                success: function(data){
                    jQuery('.fiels_label_'+data.fid).html(data.message);
                }			
            });
        });     
    });

    function strip_tags(html){

        //PROCESS STRING
        if(arguments.length < 3) {
            html=html.replace(/<\/?(?!\!)[^>]*>/gi, '');
        } else {
            var allowed = arguments[1];
            var specified = eval("["+arguments[2]+"]");
            if(allowed){
                var regex='</?(?!(' + specified.join('|') + '))\b[^>]*>';
                html=html.replace(new RegExp(regex, 'gi'), '');
            } else{
                var regex='</?(' + specified.join('|') + ')\b[^>]*>';
                html=html.replace(new RegExp(regex, 'gi'), '');
            }
        }

        //CHANGE NAME TO CLEAN JUST BECAUSE
        var clean_string = html;

        //RETURN THE CLEAN STRING
        return clean_string;
    }

    function FCKeditor_OnComplete(editorInstance) {
        editorInstance.Events.AttachEvent('OnSelectionChange', counterword);
        editorInstance.Events.AttachEvent('OnSelectionChange', counterworddes);
    }

    function counterword(){
        var oEditor = FCKeditorAPI.GetInstance('ProductProductsReturnPolicy') ;
        var pageValue = oEditor.GetHTML(true);
        var hh=strip_tags(pageValue);
        var leth=hh.length;
        var remain=(2000-leth);
        if(remain<0){
            remain=0;           
        }   
        document.getElementById('returnplicy').innerHTML = remain;
    }

    function counterworddes(){
        var oEditor = FCKeditorAPI.GetInstance('ProductProductsDescription') ;
        var pageValue = oEditor.GetHTML(true);
        var hh=strip_tags(pageValue);
        var leth=hh.length;
        var remain=(2000-leth);
        if(remain<0){
            remain=0;
        }
        document.getElementById('counter2').innerHTML = remain;
    }

    function Othervalue(fid,selectvalue){
        if(selectvalue=="Other" || selectvalue=="Others" || selectvalue=="other" || selectvalue=="others")
        {
            jQuery("#other_"+fid).show().fadeIn("250");
        }else{
            jQuery("#other_"+fid).hide().fadeOut("250");
        }
    }

</script>

<style type="text/css">
    .selectcatstyle{float:left;}.hideContent{display:none;}td{border:0;}
</style>
<?php echo $this->Html->css(array('jquery.autocomplete')); ?>
